﻿using System.Windows;
using System.Windows.Input;
using WPFToolBarExample.Helper;
using WPFToolBarExample.View;
using WPFToolBarExample.ViewModel;

namespace WPFToolBarExample.Model
{
  public class StudentModel : BaseViewModel
  {
    #region Private Member Variables

    private string _name = string.Empty;
    private string _class = string.Empty;
    private CourseModel _college = null;
    private ICommand _closeCommand;

    #endregion

    #region Public Properties

    public NewStudentView View { get; set; }

    public string Name
    {
      get { return _name; }
      set
      {
        _name = value;
        OnPropertyChanged(() => this.Name);
      }
    }

    public string Class
    {
      get { return _class; }
      set
      {
        _class = value;
        OnPropertyChanged(() => this.Class);
      }
    }

    public CourseModel College
    {
      get { return _college; }
      set
      {
        _college = value;
        OnPropertyChanged(() => this.College);
      }
    }

    public ICommand CloseCommand
    {
      get
      {
        if (_closeCommand == null)
          _closeCommand = new RelayCommand(param => CloseCommand_Execute(param), param => CloseCommand_CanExcute(param));

        return _closeCommand;
      }

    }

    private void CloseCommand_Execute(object param)
    {
      this.View.Close();
    }

    private bool CloseCommand_CanExcute(object param)
    {
      return true;
    }

    #endregion

    internal void ShowDialog()
    {
      View.ShowDialog();
    }

    public override void Save()
    {
      base.Save();
      MessageBox.Show("Saving Student : " + this.Name, "Save Student", MessageBoxButton.OK,
        MessageBoxImage.Information);
    }
  }
}
